package com.wyh.controller;


import com.wyh.common.annotation.Log;
import com.wyh.common.annotation.RateLimiter;
import com.wyh.common.enums.BusinessType;
import com.wyh.common.response.PageInfo;
import com.wyh.common.result.R;
import com.wyh.common.util.ExcelUtils;
import com.wyh.entity.AdminEconomicMan;
import com.wyh.request.AdminEconomicManRequest;
import com.wyh.service.IAdminEconomicManService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 经纪人接口控制层
 *
 * @author WangYuHang
 * @date 2024-03-03
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "经纪人接口接口管理",tags = "经纪人接口接口管理")
@RequestMapping("/admin/adminEconomicMan" )
public class AdminEconomicManController {

    private final IAdminEconomicManService iAdminEconomicManService;

    /**
     * 分页查询经纪人接口列表
     */
    @ApiOperation(value = "分页查询经纪人接口列表")
    @PostMapping("/pageList")
    public R<PageInfo<AdminEconomicMan>> pageList(@RequestBody AdminEconomicManRequest adminEconomicManRequest) {
        return R.success(iAdminEconomicManService.pageList(adminEconomicManRequest));
    }

    /**
     * 获取经纪人接口详细信息
     */
    @ApiOperation(value = "获取经纪人接口详细信息")
    @GetMapping(value = "/query/{id}")
    public R<AdminEconomicMan> detail(@PathVariable("id") Integer id) {
        return R.success(iAdminEconomicManService.getById(id));
    }

    /**
     * 新增经纪人接口
     */
    @Log(title = "新增经纪人接口", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增经纪人接口")
    @PostMapping("/add")
    public R<Void> add(@RequestBody AdminEconomicManRequest adminEconomicManRequest) {
        iAdminEconomicManService.add(adminEconomicManRequest);
        return R.success();
    }

    /**
     * 修改经纪人接口
     */
    @Log(title = "修改经纪人接口", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改经纪人接口")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody AdminEconomicManRequest adminEconomicManRequest) {
        iAdminEconomicManService.update(adminEconomicManRequest);
        return R.success();
    }

    /**
     * 删除经纪人接口
     */
    @Log(title = "删除经纪人接口", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除经纪人接口")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Integer[] ids) {
        iAdminEconomicManService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出经纪人接口
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody AdminEconomicManRequest adminEconomicManRequest) throws IOException {
        List<AdminEconomicMan> list = iAdminEconomicManService.list(adminEconomicManRequest);
        ExcelUtils.exportExcel(list, AdminEconomicMan.class, "经纪人接口信息", response);
    }
}
